package com.wlcorp.forcazamis.web.action.system;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wlcorp.forcazamis.domain.system.Staff;
import com.wlcorp.forcazamis.sys.util.ContextUtil;
import com.wlcorp.forcazamis.sys.util.SessionValue;
import com.wlcorp.forcazamis.sys.util.WebUtil;

public class LoginAction extends DispatchAction {
	public ActionForward login(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		Staff staff = new Staff();
		WebUtil.setRequestToObject(request,staff);
		staff = ContextUtil.getInstance().getStaffService().getStaffByCodeAndPassword(staff.getStaffCode(),staff.getPassword());
		if(null != staff){//登陆成功
			SessionValue.getInstance(request).setStaff(staff);
			staff.setPermission(staff.getRole().getPermission().split("\\|"));
			return mapping.findForward("main");
		}
		WebUtil.setAlertMessage(request,"用户名和密码不正确，请重新登录！");
		return mapping.findForward("login");
	}
	
}
